package com.dwxt.mall.admin.controller;

import com.dwxt.common.annotation.ValidateFiled;
import com.dwxt.common.annotation.ValidateGroup;
import com.dwxt.common.base.BaseResult;
import com.dwxt.common.base.StatusCode;
import com.dwxt.mall.admin.service.MallIndexServiceAdmin;
import com.dwxt.mall.admin.service.ProductServiceAdmin;
import com.dwxt.mall.entity.MallIndex;
import com.dwxt.mall.entity.Product;
import com.dwxt.mall.entity.vo.ProductVO;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RequestMapping("/mall/index")
@RestController
public class MallIndexControllerAdmin {

    @Autowired
    private ProductServiceAdmin productServiceAdmin;

    @Autowired
    private MallIndexServiceAdmin mallIndexServiceAdmin;

    //商城首页管理
    @RequestMapping("/selectIndexPage")
    public BaseResult selectIndexPage(Integer pageNum, Integer pageSize, Product product) {
        PageHelper.startPage(pageNum, pageSize);
        return productServiceAdmin.selectIndexList(product);
    }

    @RequestMapping("/delete")
    public BaseResult delete(Integer id){
        mallIndexServiceAdmin.delete(id);
        return BaseResult.ok();
    }

    @RequestMapping("/createOrUpdateIndex")
    @ValidateGroup(fileds = {
            @ValidateFiled(index = 0,filedName = "productId",notNull = true)
    })
    public BaseResult createOrUpdateIndex(MallIndex mallIndex){

        return mallIndexServiceAdmin.createOrUpdateIndex(mallIndex);
        //return BaseResult.ok();
    }
}
